<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        
        const A = [1,2,3]
        const B = [2,3,4]
        const setA = new Set(A)
        const setB = new Set(B)

        //  场景1. 合并两个数组 并去重  (并集)
        const res1 = new Set ([...setA,...setB])
        console.log(res1);


        // 场景2.  取两个数组共有部分  (交集)
        const res2 = new Set([...setA].filter(item => setB.has(item) ))
        console.log(res2);

        // 场景3.   取 A 对 B 的差集
        const res3 = new Set([...setA].filter(item => !setB.has(item) ))
        console.log(res3);


    </script>
</body>
</html>